-
Notifications
You must be signed in to change notification settings - Fork 46
Revive TracingMacros and @Traced #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This is defined as a separate product so that users who don't want to pay the compile-time cost of macros don't have to use it, you opt-in to that cost by depending on the TracingMacros module. The @Traced macro is only available in Swift 6.0 compilers since function body macros were introduced in Swift 6.0. This adds minimum OS versions for Apple platforms in order to be able to depend on SwiftSyntax. This applies to the whole package since there are no per-target platform specifications. Most notably: This raises the macOS minimum deployment target from the (implicit) 10.13 to 10.15.
Based on the effects signature of the attached function we apply try/await as appropriate. But, if the function is async/throws but those effects aren't actually used in the function body, this causes a new warning because the closure isn't inferred to be async and/or throws. To avoid those warnings, we also apply matching effects specifiers to the withSpan closure.
First, allow overriding the regular parameters of the withSpan call: setting the operationName, the context, and the kind. If it's not specified, it's not passed to the function, which means the function remains the source of truth for default arguments. Also allow overriding the span name, which controls the variable binding in the closure body. This is primarily useful for avoiding shadowing an outer "span" variable.
**Motivation:** We want to allow richer customization of the operation name in the `@Traced` macro, in particular the difference between the different ways you can view a function name. **Modifications:** - Add a TracedOperationName type that represents the kinds of operation names we want to support. - Change the `@Traced` macro interface and expansion to use the new operation name type. **Result:** Now you can write `@Traced(.baseName)`, `@Traced(.fullName)` as well as `@Traced("custom name here")`, giving more flexibility between types of operation names.
Heh, I forgot about the trouble with platform bump here... We may put it into a separate package -- we could do a new package that is specifically just swift-distributed-tracing-macros. |
Have we considered putting the macros into the main module behind an opt-in trait, and the trait only being defined in a 6.1-specific manifest? Having to add an explicit product dependency and then a separate import seems like a less ergonomic solution than a trait that you enable in one place, and then in your whole codebase you can use the macro with your existing |
This brings back, and will polish up a bit the
@Traced
macro that was initially pitched over here #157 by @porglezomp.I'm signing up for long term maintenance of the macro, and we need to post about expectations and rules of macro use/adoption in libraries, but we should not outright ban them.
Resolves #125